package com.bolehui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bolehui.base.result.Result;
import com.bolehui.domain.po.Jobpreference;
import com.bolehui.domain.vo.PreferenceVO;
import com.bolehui.mapper.JobpreferenceMapper;
import com.bolehui.service.JobpreferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chendongjie
 * @since 2025-03-18
 */
@Service
public class JobpreferenceServiceImpl extends ServiceImpl<JobpreferenceMapper, Jobpreference> implements JobpreferenceService {

    @Autowired
    private JobpreferenceMapper jobpreferenceMapper;
    @Override
    public Result saveJobPr(PreferenceVO preferenceVO, Long userId) {
        Jobpreference jobpreference = Jobpreference.builder()
                .jobType(preferenceVO.getType())
                .preferredCity(preferenceVO.getCity())
                .preferredIndustry(preferenceVO.getIndustry())
                .preferredJobTitle(preferenceVO.getJob())
                .maxSalary(preferenceVO.getMaxValue())
                .minSalary(preferenceVO.getMinValue())
                .candidateId(userId)
                .build();
        jobpreferenceMapper.insert(jobpreference);
        return Result.success();
    }

    @Override
    public Result update(PreferenceVO preferenceVO, Long userId) {
        Jobpreference jobpreference = Jobpreference.builder()
                .jobType(preferenceVO.getType())
                .preferredCity(preferenceVO.getCity())
                .preferredIndustry(preferenceVO.getIndustry())
                .preferredJobTitle(preferenceVO.getJob())
                .maxSalary(preferenceVO.getMaxValue())
                .minSalary(preferenceVO.getMinValue())
                .build();
        jobpreferenceMapper.update(jobpreference, new QueryWrapper<Jobpreference>().eq("candidate_id",userId));
        return Result.success();
    }
}
